package com.estate.struts.actions;

import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.estate.business.ManageProjectService;
import com.estate.business.ProFileService;
import com.estate.business.UserInfoService;
import com.estate.utils.ManageProStateUtil;
import com.estate.utils.ManageProStepUtil;
import com.estate.vo.Vo;
import com.estate.vo.impl.ManageProjectVo;
import com.estate.vo.impl.UserInfoVo;

public class ManageProAction extends EstateSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int id;
	private String proName;				//项目名称
	private String proNum;				//项目编号
	private String contactName;			//项目联系人
	private String contactPhone;		//项目联系电话
	private String delegateCompany;		//委托单位名称
	private String delegateUser;		//委托单位联系人
	private String delegatePhone;		//委托人电话
	private int currentStep;			//当前步骤
	private String recordUserId;		//提交人
	private String manageUser;		    //办理人
	private String consultName;			//咨询人员
	private String consultPhone;		//咨询人员联系方式
	private int state;					//状态
	private Date recordDate;			//项目登记日期
	private String implPlan;
	private String implProgram;
	
	private ManageProjectService manageProjectService;
	private ProFileService proFileService;
	private UserInfoService userInfoService;
	private String method;
	private String multiType;
	private int sessionUserId;
	private String sessionUserName;
	private String implement;
	private int proCatagory;
	private String method2;
	
	
	public String execute() throws Exception {
		System.out.println("Method In ManageProAction ==================================" + method);
		String page = "";
		sessionUserId = this.getSessionUser().getId();
		sessionUserName = this.getSessionUser().getName();
		ServletActionContext.getRequest().setAttribute("sessionUserId",sessionUserId);
		ServletActionContext.getRequest().setAttribute("sessionUserName",sessionUserName);
		if(method.equals("list")){
			
			if(this.getMultiType() != null && this.getMultiType().equals("true")){
				this.getRequest().setAttribute("multiType", new Boolean(true));
			}else{
				this.getRequest().setAttribute("multiType", new Boolean(false));				
			}
			
			List<Vo> manageProlist = this.getManageProjectService().findAllManageProject();
			ServletActionContext.getRequest().setAttribute("manageProlist",manageProlist);
			page = "projRegister";
		}else if(method.equals("delete")){
			Vo manageProjectVo = this.getManageProjectService().getManageProjectByPK(id);
			this.getManageProjectService().deleteManageProjectVo((ManageProjectVo) manageProjectVo);
			page=SUCCESS;
			
		}else if(method.equals("detail")){
			ManageProjectVo managePro = (ManageProjectVo) this.getManageProjectService().getManageProjectByPK(id);
			this.getRequest().setAttribute("programList", proFileService.getFileList(31, id));
			this.getRequest().setAttribute("planList", proFileService.getFileList(32, id));
			this.getRequest().setAttribute("fileList", proFileService.getFileList(3, id));
			if(managePro == null){
				page = "fail";
			}else{
				String manageProState = ManageProStateUtil.getManageProStateString(managePro.getState());
				String manageProStep = ManageProStepUtil.getManageProStepString(managePro.getCurrentStep());
				this.getRequest().setAttribute("managePro_State", manageProState);
				this.getRequest().setAttribute("managePro_Step", manageProStep);
				this.getRequest().setAttribute("managePro", managePro);
				
				page = "detail";
			}
			
		}else if(method.equals("modify")){
			System.out.println(this.getId());
			Vo vo = this.getManageProjectService().getManageProjectByPK(id);
			this.getRequest().setAttribute("programList", proFileService.getFileList(31, id));
			this.getRequest().setAttribute("planList", proFileService.getFileList(32, id));
			this.getRequest().setAttribute("fileList", proFileService.getFileList(3, id));
			if(vo == null){
				page="fail";
			}else{
				generateDropDownMenu();
				this.getRequest().setAttribute("manageProVo", vo);
				page="update";
			}
		}else if(method.equals("update")){
			ManageProjectVo manageProVo = this.getManageProject();
			System.out.println("id========="+id);
			manageProVo.setId(id);
			this.getManageProjectService().updateManageProjectVo(manageProVo);
			page=SUCCESS;
		}else if(method.equals("addpre")){
			generateDropDownMenu();
			page="add";
		}else if(method.equals("add")){
			ManageProjectVo manageProjectVo = this.getManageProject();
			if(manageProjectVo != null){
				this.getManageProjectService().addManageProject(manageProjectVo);
				page = SUCCESS;	
			}else{
				page = "fail";
			}
		}else if(method.equals("process")){
			if(this.getMultiType() != null && this.getMultiType().equals("true")){
				this.getRequest().setAttribute("multiType", new Boolean(true));
			}else{
				this.getRequest().setAttribute("multiType", new Boolean(false));				
			}
			List<Vo> manageProListInProcess = this.getManageProjectService().findManageProjectByRecordUser(sessionUserId);
			if(manageProListInProcess!=null){
			ServletActionContext.getRequest().setAttribute("manageProListInProcess",manageProListInProcess);
			page = "projProcess";
			}else{
				page = "fail";
			}
			
		}else if(method.equals("announce")){
			ManageProjectVo managePro = (ManageProjectVo) this.getManageProjectService().getManageProjectByPK(id);
			managePro.setState(state);
			this.getManageProjectService().updateManageProjectVo(managePro);
			page = "proProcessList";
		}else if(method.equals("track")){
			if(this.getMultiType() != null && this.getMultiType().equals("true")){
				this.getRequest().setAttribute("multiType", new Boolean(true));
			}else{
				this.getRequest().setAttribute("multiType", new Boolean(false));				
			}
			List<Vo> manageProListInTrack = this.getManageProjectService().findManageProjectByRecordUser(sessionUserId);
			if(manageProListInTrack!=null){
			ServletActionContext.getRequest().setAttribute("manageProListInTrack",manageProListInTrack);
			page = "projTrack";
			}else{
				page = "fail";
			}
			
		}else if(method.equals("push")){
			ManageProjectVo managePro = (ManageProjectVo) this.getManageProjectService().getManageProjectByPK(id);
			int newCurrentStep = managePro.getCurrentStep()+1;
			managePro.setCurrentStep(newCurrentStep);
			this.getManageProjectService().updateManageProjectVo(managePro);
			page = "proTrackList";
			
		}else if(method.equals("back")){
			ManageProjectVo managePro = (ManageProjectVo) this.getManageProjectService().getManageProjectByPK(id);
			int newCurrentStep = managePro.getCurrentStep()-1;
			managePro.setCurrentStep(newCurrentStep);
			this.getManageProjectService().updateManageProjectVo(managePro);
			page = "proTrackList";
			
		}else if(method.equals("mylist")){
			if(this.getMultiType() != null && this.getMultiType().equals("true")){
				this.getRequest().setAttribute("multiType", new Boolean(true));
			}else{
				this.getRequest().setAttribute("multiType", new Boolean(false));				
			}
			List<Vo> manageProlist = this.getManageProjectService().findManageProjectByRecordUser(sessionUserId);
			if(manageProlist!=null){
			ServletActionContext.getRequest().setAttribute("manageProlist",manageProlist);
			page = "projRegister";
			}else{
				page = "fail";
			}
			
		}
		return page;
	
	}
	
	
	private ManageProjectVo getManageProject() {
		ManageProjectVo managePro = new ManageProjectVo();
		managePro.setProNum(proNum);
		managePro.setImplPlan(implPlan);
		managePro.setImplProgram(implProgram);
		managePro.setProName(proName);
		managePro.setDelegateCompany(delegateCompany);
		managePro.setDelegateUser(delegateUser);
		managePro.setDelegatePhone(delegatePhone);
		UserInfoVo mUser = (UserInfoVo) this.getUserInfoService().getUserInfo(Integer.parseInt(manageUser));
		managePro.setManageUser(mUser);
		managePro.setContactName(contactName);
		managePro.setContactPhone(contactPhone);
		managePro.setConsultName(consultName);
		managePro.setConsultPhone(consultPhone);
		////////////////////////////////////////////////
		managePro.setRecordDate(recordDate);
		UserInfoVo rUser = (UserInfoVo) this.getUserInfoService().getUserInfo(Integer.parseInt(recordUserId));
		managePro.setRecordUserId(rUser);
		managePro.setState(state);
		managePro.setCurrentStep(currentStep);
		return managePro;
	}


	private List<Vo> generateDropDownMenu() {
		List<Vo> userList = this.getUserInfoService().getAllUserInfo();
		this.getRequest().setAttribute("userMenu", userList);
		return userList;
		
		
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getProName() {
		return proName;
	}
	public void setProName(String proName) {
		this.proName = proName;
	}
	public String getProNum() {
		return proNum;
	}
	public void setProNum(String proNum) {
		this.proNum = proNum;
	}
	public String getContactName() {
		return contactName;
	}
	public void setContactName(String contactName) {
		this.contactName = contactName;
	}
	public String getContactPhone() {
		return contactPhone;
	}
	public void setContactPhone(String contactPhone) {
		this.contactPhone = contactPhone;
	}
	public String getDelegateCompany() {
		return delegateCompany;
	}
	public void setDelegateCompany(String delegateCompany) {
		this.delegateCompany = delegateCompany;
	}
	public String getDelegateUser() {
		return delegateUser;
	}
	public void setDelegateUser(String delegateUser) {
		this.delegateUser = delegateUser;
	}
	public String getDelegatePhone() {
		return delegatePhone;
	}
	public void setDelegatePhone(String delegatePhone) {
		this.delegatePhone = delegatePhone;
	}
	public int getCurrentStep() {
		return currentStep;
	}
	public void setCurrentStep(int currentStep) {
		this.currentStep = currentStep;
	}
	public String getRecordUserId() {
		return recordUserId;
	}
	public void setRecordUserId(String recordUserId) {
		this.recordUserId = recordUserId;
	}
	
	public String getManageUser() {
		return manageUser;
	}
	public void setManageUser(String manageUser) {
		this.manageUser = manageUser;
	}
	public String getConsultName() {
		return consultName;
	}
	public void setConsultName(String consultName) {
		this.consultName = consultName;
	}
	public String getConsultPhone() {
		return consultPhone;
	}
	public void setConsultPhone(String consultPhone) {
		this.consultPhone = consultPhone;
	}
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	public Date getRecordDate() {
		return recordDate;
	}
	public void setRecordDate(Date recordDate) {
		this.recordDate = recordDate;
	}
	
	public ManageProjectService getManageProjectService() {
		return manageProjectService;
	}
	public void setManageProjectService(ManageProjectService manageProjectService) {
		this.manageProjectService = manageProjectService;
	}
	public UserInfoService getUserInfoService() {
		return userInfoService;
	}
	public void setUserInfoService(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}
	public String getMethod() {
		return method;
	}
	public void setMethod(String method) {
		this.method = method;
	}
	public String getMultiType() {
		return multiType;
	}

	public void setMultiType(String multiType) {
		this.multiType = multiType;
	}
	public int getSessionUserId() {
		return sessionUserId;
	}
	public void setSessionUserId(int sessionUserId) {
		this.sessionUserId = sessionUserId;
	}


	public String getSessionUserName() {
		return sessionUserName;
	}
	public void setSessionUserName(String sessionUserName) {
		this.sessionUserName = sessionUserName;
	}


	public void setProFileService(ProFileService proFileService) {
		this.proFileService = proFileService;
	}


	public ProFileService getProFileService() {
		return proFileService;
	}


	public void setImplement(String implement) {
		this.implement = implement;
	}


	public String getImplement() {
		return implement;
	}


	public void setProCatagory(int proCatagory) {
		this.proCatagory = proCatagory;
	}


	public int getProCatagory() {
		return proCatagory;
	}


	public void setMethod2(String method2) {
		this.method2 = method2;
	}


	public String getMethod2() {
		return method2;
	}


	public void setImplPlan(String implPlan) {
		this.implPlan = implPlan;
	}


	public String getImplPlan() {
		return implPlan;
	}


	public void setImplProgram(String implProgram) {
		this.implProgram = implProgram;
	}


	public String getImplProgram() {
		return implProgram;
	}


	




	



	

}
